package com.zzyl.nursing.service.impl;

import java.time.LocalDateTime;
import java.util.*;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.zzyl.common.ai.AIModelInvoker;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.exception.base.BaseException;
import com.zzyl.common.utils.PDFUtil;
import com.zzyl.common.utils.StringUtils;
import com.zzyl.nursing.dto.HealthAssessmentDto;
import com.zzyl.nursing.vo.health.HealthReportVo;
import com.zzyl.oss.client.OSSAliyunFileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.HealthAssessmentMapper;
import com.zzyl.nursing.domain.HealthAssessment;
import com.zzyl.nursing.service.IHealthAssessmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.multipart.MultipartFile;

/**
 * 健康评估Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@Service
public class HealthAssessmentServiceImpl extends ServiceImpl<HealthAssessmentMapper,HealthAssessment> implements IHealthAssessmentService
{
    @Autowired
    private HealthAssessmentMapper healthAssessmentMapper;

    /**
     * 查询健康评估
     * 
     * @param id 健康评估主键
     * @return 健康评估
     */
    @Override
    public HealthAssessment selectHealthAssessmentById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询健康评估列表
     * 
     * @param healthAssessment 健康评估
     * @return 健康评估
     */
    @Override
    public List<HealthAssessment> selectHealthAssessmentList(HealthAssessment healthAssessment)
    {
        return healthAssessmentMapper.selectHealthAssessmentList(healthAssessment);
    }

    /**
     * 新增健康评估
     * 
     * @param healthAssessment 健康评估
     * @return 结果
     */
    @Override
    public int insertHealthAssessment(HealthAssessment healthAssessment)
    {
        return save(healthAssessment)?1:0;
    }

    /**
     * 修改健康评估
     * 
     * @param healthAssessment 健康评估
     * @return 结果
     */
    @Override
    public int updateHealthAssessment(HealthAssessment healthAssessment)
    {
        return updateById(healthAssessment)?1:0;
    }

    /**
     * 批量删除健康评估
     * 
     * @param ids 需要删除的健康评估主键
     * @return 结果
     */
    @Override
    public int deleteHealthAssessmentByIds(Long[] ids)
    {
        return removeByIds(Arrays.asList(ids))?1:0;
    }

    /**
     * 删除健康评估信息
     * 
     * @param id 健康评估主键
     * @return 结果
     */
    @Override
    public int deleteHealthAssessmentById(Long id)
    {
        return removeById(id)?1:0;
    }

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private OSSAliyunFileStorageService ossAliyunFileStorageService;

    @Override
    public AjaxResult upload(MultipartFile file, String idCardNo) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String fileName = originalFilename + UUID.randomUUID().toString() + ".pdf";
        String url = ossAliyunFileStorageService.store(fileName, file.getInputStream());

        String content = PDFUtil.pdfToString(file.getInputStream());

        redisTemplate.boundValueOps("healthReport"+idCardNo).set(content);
        AjaxResult a = AjaxResult.success();
        a.put("fileName", url);
        a.put("url",url);
        a.put("originalFilename",originalFilename);
        return a;
    }

    @Autowired
    private AIModelInvoker aiModelInvoker;

    @Override
    public Long addHealthAssessment(HealthAssessmentDto dto) {
        //1、根据身份证号是否正确
        String content = redisTemplate.boundValueOps("healthReport" + dto.getIdCard()).get();
        if(content ==null){
            throw new BaseException("请上传或重新上传体检报告");
        }
        //2、拼接提示词
        String prompt = getPrompt(content);
        //3、调用大模型

        String string = qianfanInvoker2(prompt);
        HealthReportVo bean = JSONUtil.toBean(string,HealthReportVo.class);
        //5、保存表
        HealthAssessment healthAssessment = new HealthAssessment();

        healthAssessment.setElderName(dto.getElderName());
        healthAssessment.setIdCard(dto.getIdCard());

        DateTime birthDate = IdcardUtil.getBirthDate(dto.getIdCard());
        healthAssessment.setBirthDate(birthDate.toLocalDateTime());

        int ageByIdCard = IdcardUtil.getAgeByIdCard(dto.getIdCard());
        healthAssessment.setAge(ageByIdCard);

        int genderByIdCard = IdcardUtil.getGenderByIdCard(dto.getIdCard());
        healthAssessment.setGender(genderByIdCard);

        double healthIndex = bean.getHealthAssessment().getHealthIndex();
        String riskLevel = bean.getHealthAssessment().getRiskLevel();

        healthAssessment.setHealthScore(String.valueOf(healthIndex));
        healthAssessment.setRiskLevel(riskLevel);

        healthAssessment.setSuggestionForAdmission(getSuggestionForAdmission(healthIndex));

        healthAssessment.setNursingLevelName(getNursingLevelName(healthIndex));

        healthAssessment.setAdmissionStatus(1);

        healthAssessment.setTotalCheckDate(bean.getTotalCheckDate());
        healthAssessment.setPhysicalExamInstitution(dto.getPhysicalExamInstitution());
        healthAssessment.setPhysicalReportUrl(dto.getPhysicalReportUrl());
        healthAssessment.setAssessmentTime(LocalDateTime.now());
        healthAssessment.setReportSummary(bean.getSummarize());
        healthAssessment.setAbnormalAnalysis(JSONUtil.toJsonStr(bean.getAbnormalData()));
        healthAssessment.setSystemScore(JSONUtil.toJsonStr(bean.getSystemScore()));

        save(healthAssessment);


        return healthAssessment.getId();
    }
    /**
     * 计算护理等级
     *
     * @param healthScore
     * @return
     */
    private String getNursingLevelName(double healthScore) {
        //处理边界
        if (healthScore < 0 || healthScore > 100) {
            throw new IllegalArgumentException("健康评分必须在0到100之间");
        }

        if(healthScore >= 60 && healthScore < 70){
            return "三级护理等级";
        }else if (healthScore >= 70 && healthScore < 80){
            return "二级护理等级";
        }else if (healthScore >= 80 && healthScore < 90){
            return "一级护理等级";
        }else if (healthScore >= 90){
            return "特级护理等级";
        }
        return "无";

    }

    /**
     * 是否建议入住
     *
     * @param healthScore
     * @return
     */
    private Integer getSuggestionForAdmission(double healthScore) {
        if (healthScore >= 60) {
            return 0;
        }
        return 1;

    }

    //拼接提示词
    private String getPrompt(String content) {
        String prompt = "请以一个专业医生的视角来分析这份体检报告，报告中包含了一些异常数据，我需要您对这些数据进行解读，并给出相应的健康建议。\n" +
                "体检内容如下：\n" +
                content + "\n" +
                "\n" +
                "要求：\n" +
                "1. 提取体检报告中的“总检日期”；\n" +
                "2. 通过临床医学、疾病风险评估模型和数据智能分析，给该用户的风险等级和健康指数给出结果。风险等级分为：健康、提示、风险、危险、严重危险。健康指数范围为0至100分；\n" +
                "3. 根据用户身体各项指标数据，详细说明该用户各项风险等级的占比是多少，最多保留两位小数。结论格式：该用户健康占比20.00%，提示占比20.00%，风险占比20%，危险占比20%，严重危险占比20%；\n" +
                "4. 对于体检报告有异常数据，请列出（异常数据的结论、体检项目名称、检查结果、参考值、单位、异常解读、建议）这8字段。解读异常数据，解决这些数据可能代表的健康问题或风险。分析可能的原因，包括但不限于生活习惯、饮食习惯、遗传因素等。基于这些异常数据和可能的原因，请给出具体的健康建议，包括饮食调整、运动建议、生活方式改变以及是否需要进一步检查或治疗等。\n" +
                "结论格式：异常数据的结论：肥胖，体检项目名称：体重指数BMI，检查结果：29.2，参考值>24，单位：-。异常解读：体重超标包括超重与肥胖。体重指数（BMI）=体重（kg）/身⾼（m）的平⽅，BMI≥24为超重，BMI≥28为肥胖；男性腰围≥90cm和⼥性腰围≥85cm为腹型肥胖。体重超标是⼀种由多因素（如遗传、进⻝油脂较多、运动少、疾病等）引起的慢性代谢性疾病，尤其是肥胖，已经被世界卫⽣组织列为导致疾病负担的⼗⼤危险因素之⼀。AI建议：采取综合措施预防和控制体重，积极改变⽣活⽅式，宜低脂、低糖、⾼纤维素膳⻝，多⻝果蔬及菌藻类⻝物，增加有氧运动。若有相关疾病（如⾎脂异常、⾼⾎压、糖尿病等）应积极治疗。\n" +
                "5. 根据这个体检报告的内容，分别是给人体的8大系统打分，每项满分为100分，8大系统分别为：呼吸系统、消化系统、内分泌系统、免疫系统、循环系统、泌尿系统、运动系统、感官系统\n" +
                "6. 给体检报告做一个总结，总结格式：体检报告中尿蛋⽩、癌胚抗原、⾎沉、空腹⾎糖、总胆固醇、⽢油三酯、低密度脂蛋⽩胆固醇、⾎清载脂蛋⽩B、动脉硬化指数、⽩细胞、平均红细胞体积、平均⾎红蛋⽩共12项指标提示异常，尿液常规共1项指标处于临界值，⾎脂、⾎液常规、尿液常规、糖类抗原、⾎清酶类等共43项指标提示正常，综合这些临床指标和数据分析：肾脏、肝胆、⼼脑⾎管存在隐患，其中⼼脑⾎管有“⾼危”⻛险；肾脏部位有“中危”⻛险；肝胆部位有“低危”⻛险。\n" +
                "\n" +
                "输出要求：\n" +
                "最后，将以上结果输出为JSON格式，不要包含其他的文字说明，所有的返回结果都是json，详细格式如下：\n" +
                "\n" +
                "{\n" +
                "  \"totalCheckDate\": \"YYYY-MM-DD\",\n" +
                "  \"healthAssessment\": {\n" +
                "    \"riskLevel\": \"healthy/caution/risk/danger/severeDanger\",\n" +
                "    \"healthIndex\": XX.XX\n" +
                "  },\n" +
                "  \"abnormalData\": [\n" +
                "    {\n" +
                "      \"conclusion\": \"异常数据的结论\",\n" +
                "      \"examinationItem\": \"体检项目名称\",\n" +
                "      \"result\": \"检查结果\",\n" +
                "      \"referenceValue\": \"参考值\",\n" +
                "      \"unit\": \"单位\",\n" +
                "      \"interpret\":\"对于异常的结论进一步详细的说明\",\n" +
                "      \"advice\":\"针对于这一项的异常，给出一些健康的建议\"\n" +
                "    }\n" +
                "  ],\n" +
                "  \"systemScore\": {\n" +
                "    \"breathingSystem\": XX,\n" +
                "    \"digestiveSystem\": XX,\n" +
                "    \"endocrineSystem\": XX,\n" +
                "    \"immuneSystem\": XX,\n" +
                "    \"circulatorySystem\": XX,\n" +
                "    \"urinarySystem\": XX,\n" +
                "    \"motionSystem\": XX,\n" +
                "    \"senseSystem\": XX\n" +
                "  },\n" +
                "  \"summarize\": \"体检报告的总结\"\n" +
                "}";
        return prompt;
    }
    //千帆大模型
    private HealthReportVo useLLM(String prompt){
        // 创建消息Map，包含角色和内容
        Map messageMap = Map.of("role","user","content",prompt);
        // 创建消息列表
        List messages = List.of(messageMap);
        // 创建请求体Map
        Map bodyMap = new HashMap();
        bodyMap.put("model","ernie-4.0-8k");
        bodyMap.put("max_output_tokens",2000);
        bodyMap.put("messages",messages);
        //送HTTP POST请求到百度千帆API   HttpUtil.createRequest 通用方法
        String body = HttpUtil.createRequest(Method.POST, "https://qianfan.baidubce.com/v2/chat/completions")
                // 设置头
                .header("Authorization","Bearer bce-v3/ALTAK-l7RGWNX3t8o5d2OJcC1TQ/3f241aa6a457354d7fb516893a6312c6ce67b9b5")
                // 设置body参数
                .body(JSONUtil.toJsonStr(bodyMap))//需要JSON字符串
                .execute().body();  //执行.响应体

        System.out.println(body);

        // 解析JSON响应
        JSONObject jsonObject = JSONUtil.parseObj(body);
        // 从JSON中提取AI返回的内容
        String content = jsonObject.getByPath("choices[0].message.content", String.class);
        // 清理内容中的Markdown代码块标记
        content = content.replace("```json", "");
        content = content.replace("```", "");
        // 将JSON内容转换为Java对象
        HealthReportVo healthReportVo = JSONUtil.toBean(content, HealthReportVo.class);
        return healthReportVo;
    }
    //ollama deepseek
    private HealthReportVo useLocalLLM(String prompt){
        Map messageMap = Map.of("role","user","content",prompt);

        List messages = List.of(messageMap);

        Map bodyMap = new HashMap();
        bodyMap.put("model","deepseek-r1:7b");
        bodyMap.put("max_output_tokens",4000);
        bodyMap.put("messages",messages);
        bodyMap.put("stream",false);

        String body = HttpUtil.createRequest(Method.POST, "http://localhost:11434/api/chat")
                // 设置头
                // 设置body参数  query   form
                .body(JSONUtil.toJsonStr(bodyMap))
                .execute().body();

        System.out.println(body);

        // 把json字符串转成对象
        JSONObject jsonObject = JSONUtil.parseObj(body);
        //
        String content = jsonObject.getByPath("message.content", String.class);
        // content =   "```json\n{\n\t\"totalCheckDate\": \"2023-10-10\",\n\t\"healthAssessment\": {\n\t\t\"riskLevel\": \"risk\",\n\t\t\"healthIndex\": 75.50\n\t},\n\t\"abnormalData\": [\n\t\t{\n\t\t\t\"conclusion\": \"心率略快，偶发早搏，皮肤弹性差，四肢末梢凉，提示可能的循环问题\",\n\t\t\t\"examinationItem\": \"心率\",\n\t\t\t\"result\": \"92次/分\",\n\t\t\t\"referenceValue\": \"\u003c100（正常成人静息心率）\",\n\t\t\t\"unit\": \"次/分\",\n\t\t\t\"interpret\": \"心率略快可能由多种因素引起，包括但不限于焦虑、运动、药物副作用或潜在的心脏问题。偶发早搏可能是心脏电活动异常的表现。皮肤弹性差和四肢末梢凉可能与血液循环不良有关。\",\n\t\t\t\"advice\": \"建议进行心电图检查和血管功能评估，以进一步了解心脏和血管的健康状况。同时，保持健康的生活方式，包括规律作息、适量运动和健康饮食。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"视力下降，符合老视特征\",\n\t\t\t\"examinationItem\": \"视力\",\n\t\t\t\"result\": \"左眼0.3，右眼0.4\",\n\t\t\t\"referenceValue\": \"正常视力应接近1.0\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"视力下降可能是老视（老花眼）的表现，这是随着年龄增长而出现的正常生理现象。\",\n\t\t\t\"advice\": \"建议定期复查视力，并考虑配戴老花镜以改善视力。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"口腔粘膜轻微炎症，唇部干燥脱屑，牙齿部分缺失伴有较多牙石，牙周炎及牙龈退缩\",\n\t\t\t\"examinationItem\": \"口腔检查\",\n\t\t\t\"result\": \"口腔粘膜轻微炎症，唇部干燥脱屑，牙齿部分缺失，余牙石较多，牙周炎，牙龈退缩\",\n\t\t\t\"referenceValue\": \"口腔粘膜无炎症，唇部湿润，牙齿完整无牙石，牙周健康\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"口腔粘膜炎症和唇部干燥脱屑可能与口腔卫生不良、缺水或维生素缺乏有关。牙齿部分缺失、牙石和牙周炎是口腔健康问题的表现，可能导致牙齿松动和脱落。\",\n\t\t\t\"advice\": \"建议口腔科进一步检查和治疗，包括清洁牙齿、治疗牙周炎和补充必要的维生素。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"轻度脂肪肝可能\",\n\t\t\t\"examinationItem\": \"肝脏B超\",\n\t\t\t\"result\": \"肝脏实质回声略粗糙\",\n\t\t\t\"referenceValue\": \"肝脏实质回声均匀\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"轻度脂肪肝可能与肥胖、高脂饮食、缺乏运动或酒精摄入过多有关。\",\n\t\t\t\"advice\": \"建议调整饮食，减少高脂食物摄入，增加有氧运动，限制酒精摄入，并定期复查肝脏B超。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"胆囊壁毛糙，考虑慢性胆囊炎可能\",\n\t\t\t\"examinationItem\": \"胆囊B超\",\n\t\t\t\"result\": \"胆囊壁毛糙\",\n\t\t\t\"referenceValue\": \"胆囊壁光滑\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"胆囊壁毛糙可能是慢性胆囊炎的表现，与胆囊内结石、感染或胆汁淤积有关。\",\n\t\t\t\"advice\": \"建议进一步检查胆囊功能，如有必要，进行胆囊炎的治疗。同时，保持低脂饮食，避免暴饮暴食。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"脾轻度增大\",\n\t\t\t\"examinationItem\": \"脾脏B超\",\n\t\t\t\"result\": \"脾轻度增大\",\n\t\t\t\"referenceValue\": \"脾大小正常\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"脾轻度增大可能与感染、炎症、血液疾病或肝脏疾病有关。\",\n\t\t\t\"advice\": \"建议进一步检查脾脏功能和相关疾病，以确定脾增大的原因并进行相应治疗。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"右肾小囊肿可能\",\n\t\t\t\"examinationItem\": \"肾脏B超\",\n\t\t\t\"result\": \"右肾下极见一大小约5mm的无回声区\",\n\t\t\t\"referenceValue\": \"肾脏无异常回声区\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"右肾小囊肿可能是肾脏的良性病变，通常无需特殊治疗，但需定期监测其大小变化。\",\n\t\t\t\"advice\": \"建议定期复查肾脏B超，以监测囊肿的大小变化。如有增大或出现症状，及时就医。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"前列腺形态略增大，回声欠均匀\",\n\t\t\t\"examinationItem\": \"前列腺B超\",\n\t\t\t\"result\": \"前列腺形态略增大，回声欠均匀\",\n\t\t\t\"referenceValue\": \"前列腺大小正常，回声均匀\",\n\t\t\t\"unit\": \"-\",\n\t\t\t\"interpret\": \"前列腺形态略增大和回声欠均匀可能与前列腺增生或炎症有关。\",\n\t\t\t\"advice\": \"建议进行前列腺特异性抗原（PSA）检查，以排除前列腺疾病。同时，保持健康的生活方式，包括适量运动和健康饮食。\"\n\t\t},\n\t\t{\n\t\t\t\"conclusion\": \"空腹血糖临界\",\n\t\t\t\"examinationItem\": \"空腹血糖\",\n\t\t\t\"result\": \"6.1mmol/L\",\n\t\t\t\"referenceValue\": \"3.9-6.1mmol/L\",\n\t\t\t\"unit\": \"mmol/L\",\n\t\t\t\"interpret\": \"空腹血糖处于临界值，可能提示糖代谢异常或糖尿病前期。\",\n\t\t\t\"advice\": \"建议控制饮食，减少高糖食物摄入，增加膳食纤维摄入，并定期复查空腹血糖和餐后血糖。\"\n\t\t}\n\t],\n\t\"systemScore\": {\n\t\t\"breathingSystem\": 95,\n\t\t\"digestiveSystem\": 80,\n\t\t\"endocrineSystem\": 85,\n\t\t\"immuneSystem\": 90,\n\t\t\"circulatorySystem\": 75,\n\t\t\"urinarySystem\": 80,\n\t\t\"motionSystem\": 95,\n\t\t\"senseSystem\": 80\n\t},\n\t\"summarize\": \"体检报告中尿蛋⽩、癌胚抗原、⾎沉均正常，空腹⾎糖处于临界值，总胆固醇、⽢油三酯、低密度脂蛋⽩胆固醇、⾎清载脂蛋⽩B、动脉硬化指数、⽩细胞、平均红细胞体积、平均⾎红蛋⽩均正常，B超提示肝脏、胆囊、脾脏、肾脏、前列腺存在异常，综合这些临床指标和数据分析：肾脏、肝胆、⼼脑⾎管存在隐患，其中⼼脑⾎管有“⾼危”⻛险，需关注心率和血管功能；肾脏部位有“中危”⻛险，建议定期监测；肝胆部位有“低危”⻛险，建议调整饮食和生活习惯。\"\n}\n```";

        content = content.replaceAll("(?s)<think>.*?</think>", "");


        content = content.replace("```json", "");

        content = content.replace("```", "");

        HealthReportVo healthReportVo = JSONUtil.toBean(content, HealthReportVo.class);
        System.out.println(healthReportVo);
        return healthReportVo;
    }
    //阿里云百炼的通义千问
    public  HealthReportVo useAliBailian(String prompt) {
        HealthReportVo healthReportVo= null;
        try {
            GenerationResult result = callWithMessage(prompt);
            String content = result.getOutput().getChoices().get(0).getMessage().getContent();
            content = content.replace("```json", "");

            content = content.replace("```", "");

            healthReportVo = JSONUtil.toBean(content, HealthReportVo.class);


        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            // 使用日志框架记录异常信息
            System.err.println("An error occurred while calling the generation service: " + e.getMessage());
        }
        return healthReportVo;
    }
    //阿里云百炼的通义千问的callWithMessage方法
    public  GenerationResult callWithMessage(String prompt) throws ApiException, NoApiKeyException, InputRequiredException {
        Generation gen = new Generation();
        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content(prompt)
                .build();
        GenerationParam param = GenerationParam.builder()

                .apiKey("sk-5a7d1ecf209a44e894560a5d81fc69db")

                .model("qwen-plus")
                .messages(Arrays.asList(  userMsg))
                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                .build();
        return gen.call(param);
    }
    //千帆返回的结果
    public String qianfanInvoker2(String prompt) {
        return "\n" +
                "{\n" +
                "  \"totalCheckDate\": \"2023-10-10\",\n" +
                "  \"healthAssessment\": {\n" +
                "    \"riskLevel\": \"risk\",\n" +
                "    \"healthIndex\": 68.50\n" +
                "  },\n" +
                "  \"abnormalData\": [\n" +
                "    {\n" +
                "      \"conclusion\": \"心率偏快伴偶发早搏\",\n" +
                "      \"examinationItem\": \"内科-心率与心律\",\n" +
                "      \"result\": \"92 次/分，偶发早搏\",\n" +
                "      \"referenceValue\": \"< 100\",\n" +
                "      \"unit\": \"次/分\",\n" +
                "      \"interpret\": \"心率略高于正常范围（静息心率通常为60-100次/分），虽仍在窦性范围内，但持续偏快可能提示交感神经兴奋性增高、心脏负荷增加或潜在心功能不全。偶发早搏常见于老年人，可能为功能性，但也可见于心肌缺血、电解质紊乱或结构性心脏病。\",\n" +
                "      \"advice\": \"建议进行24小时动态心电图（Holter）评估早搏性质及数量，排查心律失常风险；控制血压、避免咖啡因和熬夜；如有胸闷、心悸症状应尽快就诊心血管科；定期监测心率变化。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"皮肤弹性差、四肢末梢凉\",\n" +
                "      \"examinationItem\": \"内科-其他体征\",\n" +
                "      \"result\": \"皮肤弹性差，四肢末梢凉\",\n" +
                "      \"referenceValue\": \"正常应弹性良好、四肢温暖\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"提示外周循环不良，可能与动脉硬化、微循环障碍或自主神经功能失调有关，尤其在老年男性中需警惕早期外周血管疾病或心血管系统供血不足的表现。\",\n" +
                "      \"advice\": \"建议完善下肢动脉彩超、踝臂指数（ABI）检测以评估血管功能；加强保暖，戒烟限酒，控制三高（高血压、高血脂、糖尿病）危险因素；适当进行下肢有氧运动如散步、踩车改善循环。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"视力下降（老视）\",\n" +
                "      \"examinationItem\": \"眼科-视力\",\n" +
                "      \"result\": \"左眼 0.3，右眼 0.4\",\n" +
                "      \"referenceValue\": \"≥1.0\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"视力明显低于正常标准，符合年龄相关性老视表现，主要由于晶状体调节能力下降所致，同时伴有角膜老年环和结膜轻微充血，提示眼部老化过程加速。\",\n" +
                "      \"advice\": \"建议至眼科验光并配戴合适的老花镜；每年复查眼底，排除青光眼、白内障或黄斑变性等老年眼病；注意用眼卫生，避免长时间近距离用眼。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"左耳听力轻度下降\",\n" +
                "      \"examinationItem\": \"耳鼻喉科-听力\",\n" +
                "      \"result\": \"左耳听力轻度下降\",\n" +
                "      \"referenceValue\": \"正常\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"老年性耳聋早期表现，多为双侧渐进性感音神经性听力损失，本例仅单侧受累，需排除耵聍堵塞、中耳炎或其他局部病变。\",\n" +
                "      \"advice\": \"建议耳鼻喉科进一步行纯音测听检查明确听力损失类型；避免噪声暴露；保持耳道清洁；必要时考虑助听器干预。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"慢性胆囊炎可能\",\n" +
                "      \"examinationItem\": \"B超-胆囊\",\n" +
                "      \"result\": \"胆囊壁毛糙\",\n" +
                "      \"referenceValue\": \"光滑\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"胆囊壁毛糙是慢性胆囊炎的常见影像学表现，常由长期胆汁淤积、胆固醇结晶刺激或反复急性发作引起，可导致右上腹隐痛、消化不良等症状。\",\n" +
                "      \"advice\": \"建议低脂饮食，减少油腻食物摄入；避免暴饮暴食；若有右上腹不适可做胆囊收缩功能检查；定期复查腹部B超，监测胆囊壁厚度及结石形成情况。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"轻度脂肪肝可能\",\n" +
                "      \"examinationItem\": \"B超-肝脏\",\n" +
                "      \"result\": \"实质回声略粗糙\",\n" +
                "      \"referenceValue\": \"均匀细腻\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"肝脏回声增粗提示脂肪浸润，属于非酒精性脂肪肝（NAFLD）早期改变，常见于体重超标、胰岛素抵抗、血脂异常人群，若不加干预可能进展为肝纤维化甚至肝硬化。\",\n" +
                "      \"advice\": \"建议控制体重，限制精制碳水化合物和饱和脂肪摄入；增加中等强度有氧运动每周至少150分钟；复查肝功能及肝脏弹性成像（FibroScan）评估脂肪变程度。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"脾轻度增大\",\n" +
                "      \"examinationItem\": \"B超-脾脏\",\n" +
                "      \"result\": \"轻度增大，回声均匀\",\n" +
                "      \"referenceValue\": \"肋下未及\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"脾大原因多样，包括慢性感染、门脉高压、血液系统疾病或代谢性疾病。当前回声均匀且无其他血液异常，暂考虑良性可能性大，但仍需警惕潜在系统性疾病。\",\n" +
                "      \"advice\": \"建议完善血常规、肝功能、病毒性肝炎筛查及腹部增强CT/MRI进一步评估；定期随访B超观察脾脏大小变化；若有乏力、出血倾向应及时就医。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"右肾小囊肿可能\",\n" +
                "      \"examinationItem\": \"B超-肾脏\",\n" +
                "      \"result\": \"右肾下极见约5mm无回声区\",\n" +
                "      \"referenceValue\": \"未见异常\",\n" +
                "      \"unit\": \"mm\",\n" +
                "      \"interpret\": \"小肾囊肿极为常见，多为单纯性良性囊肿，随年龄增长发生率升高，一般无症状，极少影响肾功能，但需定期监测是否增大或出现复杂特征。\",\n" +
                "      \"advice\": \"无需特殊处理，建议每1-2年复查泌尿系B超；若出现腰痛或血尿则及时就诊；保持充足饮水，避免憋尿。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"前列腺形态略增大\",\n" +
                "      \"examinationItem\": \"B超-前列腺\",\n" +
                "      \"result\": \"形态略增大，回声欠均匀\",\n" +
                "      \"referenceValue\": \"正常大小（约4×3×2cm）\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"老年男性常见前列腺增生（BPH）表现，可能导致排尿困难、夜尿增多等症状，回声欠均匀也需警惕炎症或肿瘤可能，特别是前列腺癌风险随年龄上升。\",\n" +
                "      \"advice\": \"建议查前列腺特异性抗原（PSA）排除恶性病变；若有排尿异常可使用IPSS评分评估严重程度；避免饮酒及辛辣食物；必要时泌尿外科药物治疗。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"牙周炎及牙龈退缩\",\n" +
                "      \"examinationItem\": \"口腔科-牙周\",\n" +
                "      \"result\": \"牙周炎，牙龈退缩\",\n" +
                "      \"referenceValue\": \"牙龈红润紧贴牙面\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"牙周组织慢性炎症，主要由牙菌斑长期堆积引发，导致牙槽骨吸收和牙齿松动，严重者可致牙齿脱落，且与心血管疾病、糖尿病存在关联。\",\n" +
                "      \"advice\": \"建议口腔科洗牙（洁治+刮治）清除牙石；学习正确刷牙方法（巴氏刷牙法）；使用牙线和冲牙器；定期每半年复查一次；修复缺失牙以防咬合紊乱。\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"conclusion\": \"唇干燥脱屑\",\n" +
                "      \"examinationItem\": \"口腔科-唇部\",\n" +
                "      \"result\": \"干燥脱屑\",\n" +
                "      \"referenceValue\": \"湿润完整\",\n" +
                "      \"unit\": \"-\",\n" +
                "      \"interpret\": \"可能与环境干燥、维生素缺乏（如B族）、脱水或慢性唇炎有关，长期不愈可能发展为糜烂性唇炎甚至癌前病变。\",\n" +
                "      \"advice\": \"保持水分摄入；涂抹润唇膏保护屏障；补充复合维生素B；避免舔唇习惯；若持续不愈应皮肤科就诊排除扁平苔藓或光化性唇炎。\"\n" +
                "    }\n" +
                "  ],\n" +
                "  \"systemScore\": {\n" +
                "    \"breathingSystem\": 95,\n" +
                "    \"digestiveSystem\": 70,\n" +
                "    \"endocrineSystem\": 82,\n" +
                "    \"immuneSystem\": 90,\n" +
                "    \"circulatorySystem\": 65,\n" +
                "    \"urinarySystem\": 80,\n" +
                "    \"motionSystem\": 88,\n" +
                "    \"senseSystem\": 72\n" +
                "  },\n" +
                "  \"summarize\": \"体检报告中心率偏快、偶发早搏、皮肤弹性差、四肢末梢凉提示循环系统异常；B超显示轻度脂肪肝可能、胆囊壁毛糙、脾轻度增大反映肝胆系统问题；右肾小囊肿、前列腺增大提示泌尿系统隐患；视力下降、左耳听力减退属感官系统退行性改变；口腔牙周炎为运动系统相关结构病变。综合分析：循环、肝胆、泌尿系统存在不同程度风险，其中循环系统有“中危”风险；肝胆部位有“低危”风险；泌尿系统前列腺问题需警惕“中危”风险；感官系统呈自然老化趋势。空腹血糖、血脂四项、肾功能肌酐均处于临界或正常高值，提示代谢调节能力下降。免疫指标、胸部X光、尿常规等共43项指标正常，癌胚抗原、AFP、乙肝标志物等肿瘤及感染筛查未见异常。综上所述，该用户健康占比20.00%，提示占比20.00%，风险占比30.00%，危险占比20.00%，严重危险占比10.00%。\"\n" +
                "}\n";
    }

}
